﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TempCtr.Model;

namespace TempCtr
{
    public partial class FirstSetting : Form
    {
        private int ThermostatNum = 0;
        private int[] EverTheNum = new int[10];
        private int[] EverPort = new int[10];
        public FirstSetting()
        {
            InitializeComponent();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            ThermostatNum = comboBox1.SelectedIndex + 1;
            Display(comboBox1.SelectedIndex);

        }

        private void Display(int num)
        {
            bool[] state = new bool[10];
            for (int i = 0; i < 10; i++)
            {
                if (i <= num) state[i] = true;
                else state[i] = false;
            }
            panel1.Visible = state[0];
            panel2.Visible = state[1];
            panel3.Visible = state[2];
            panel4.Visible = state[3];
            panel5.Visible = state[4];
            panel6.Visible = state[5];
            panel7.Visible = state[6];
            panel8.Visible = state[7];
            panel9.Visible = state[8];
            panel10.Visible = state[9];


            this.Height = 330+num*67;
            button1.Location = new Point(337, 190+num*65);
            button1.Visible = true;
        }


        private void FirstSetting_Load(object sender, EventArgs e)
        {
            comboBox1.SelectedIndex = 0;
            comboBox2.SelectedIndex = 20;
            comboBox3.SelectedIndex = 20;
            comboBox4.SelectedIndex = 20;
            comboBox5.SelectedIndex = 20;
            comboBox6.SelectedIndex = 20;
            comboBox7.SelectedIndex = 20;
            comboBox8.SelectedIndex = 20;
            comboBox9.SelectedIndex = 20;
            comboBox10.SelectedIndex = 20;
            comboBox11.SelectedIndex = 20;
            comboBox12.SelectedIndex = 1;
            comboBox13.SelectedIndex = 2;
            comboBox14.SelectedIndex = 3;
            comboBox15.SelectedIndex = 4;
            comboBox16.SelectedIndex = 5;
            comboBox17.SelectedIndex = 6;
            comboBox18.SelectedIndex = 7;
            comboBox19.SelectedIndex = 8;
            comboBox20.SelectedIndex = 9;
            comboBox21.SelectedIndex = 10;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            EverPort[0] = comboBox12.SelectedIndex+1;
            EverPort[1] = comboBox13.SelectedIndex+1;
            EverPort[2] = comboBox14.SelectedIndex+1;
            EverPort[3] = comboBox15.SelectedIndex+1;
            EverPort[4] = comboBox16.SelectedIndex+1;
            EverPort[5] = comboBox17.SelectedIndex+1;
            EverPort[6] = comboBox18.SelectedIndex+1;
            EverPort[7] = comboBox19.SelectedIndex+1;
            EverPort[8] = comboBox20.SelectedIndex+1;
            EverPort[9] = comboBox21.SelectedIndex+1;

            EverTheNum[0] = comboBox2.SelectedIndex;
            EverTheNum[1] = comboBox3.SelectedIndex;
            EverTheNum[2] = comboBox4.SelectedIndex;
            EverTheNum[3] = comboBox5.SelectedIndex;
            EverTheNum[4] = comboBox6.SelectedIndex;
            EverTheNum[5] = comboBox7.SelectedIndex;
            EverTheNum[6] = comboBox8.SelectedIndex;
            EverTheNum[7] = comboBox9.SelectedIndex;
            EverTheNum[8] = comboBox10.SelectedIndex;
            EverTheNum[9] = comboBox11.SelectedIndex;

            for (int i = 0; i < ThermostatNum; i++)
            {
                for (int j = 0; j < EverTheNum[i]; j++)
                {
                    Console.Write("i="+i,"j="+j);
                    MySqlHelp.ADDThermostat(i*32+j+1,"COM"+EverPort[i].ToString(),j+1,i+1);
                }
            }

            this.Close();
        }
    }
}
